package test4;

import java.util.Scanner;

public class StartConvert {
    public static void main(String[] args) {
        //预设大写数字
        String[] convert = {"零","壹","贰","叁","肆",
                "伍","陆","柒","捌","玖"};
        //预设位名
        String[] name={"","","拾","佰","仟","万","拾万","佰万","仟万","亿","拾亿"};
        //定义计算位数变量
        int count = 0;
        //定义用户输入变量
        int money=0;

        //用户输入金额
        while(true) {
            System.out.println("请输入金额（用阿拉伯数字表示）");
            Scanner sc = new Scanner(System.in);
            money = sc.nextInt();

            //计算用户输入数字的位数
            int temp=money;
            while(temp > 0){
                temp/=10;
                count++;
            }

            //判断输入是否正确
            if(money<0) {
                System.out.println("不可输入负数，请重新输入！");
            }
            else if(count > 10) {
                System.out.println("输入数字的位数不可超过10，请重新输入！");
            }
            else {
                break;
            }

        }

        //创建转换对象并预设信息
        MoneyConvert mc = new MoneyConvert(money,convert,name);
        mc.firstResult=new String[count];

        //开始转换
        //调用转换大写方法
        mc.moneyConvert();
        //调用添加位名方法并输出最终结果
        mc.addName(count);

        //输出结束信息
        System.out.println("感谢您使用本程序！");
    }

}
